package com.ics.web.controller.travelstar.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ics.framework.util.PageUtil;
import com.ics.web.controller.travelstar.domain.TbVisitorsLog;
import com.ics.web.controller.travelstar.dto.VisitorsLogDTO;
import com.ics.web.controller.travelstar.mapper.TbVisitorsLogMapper;
import com.ics.web.controller.travelstar.service.ITbVisitorsLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 访客记录Service业务层处理
 *
 * @author ics
 * @date 2024-10-22
 */
@Service
public class TbVisitorsLogServiceImpl extends ServiceImpl<TbVisitorsLogMapper, TbVisitorsLog>
        implements ITbVisitorsLogService {

    @Override
    public IPage<TbVisitorsLog> listPage(VisitorsLogDTO logDTO) {
        LambdaQueryWrapper<TbVisitorsLog> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByDesc(TbVisitorsLog::getCreateTime);

        if (StringUtils.isNotBlank(logDTO.getStartDate())) {
            wrapper.ge(TbVisitorsLog::getLoginDateTime, logDTO.getStartDate());
        }
        if (StringUtils.isNotBlank(logDTO.getEndDate())) {
            wrapper.le(TbVisitorsLog::getLoginDateTime, logDTO.getEndDate());
        }
        return this.baseMapper.selectPage(PageUtil.getPage(logDTO), wrapper);
    }
}
